<?php

namespace App\Http\Controllers\Admin;

use App\Models\Admin;
use App\Models\Brand;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;

Class LoginController extends BaseController{

    public function __construct(Admin $admin , Brand $brand)
    {
        parent::__construct();
        $this->admin = $admin;
        $this->brand = $brand;
    }

    /**
     * 获取登录界面
     */
    public function getLogin(){
         return view('login');
    }

    //提交登录
    public function postLogin()
    {
        $res = $this->admin->login(request());
        return ajax_return($res);
    }

    //注销用户
    public function getLogOut(){
//         Auth::logout();
        Session::forget('adminId');
        Session::forget('adminType');
        return redirect(urlAdmin('login', 'getLogin'));
    }

    /**
     * 用户注册页面
     */
    public function getRegister(){

        return view('register');
    }

    /**
     * 用户注册
     */
    public function postRegister(){

        $res = $this->brand->addBrand(request());
        return ajax_return($res);
    }
    //验证码
    public function getCode(){
        return verify();
    }

}